package com.sudo.service.res.service.impl;

import com.github.pagehelper.PageHelper;
import com.sudo.common.utils.PagedGridResult;
import com.sudo.dao.res.entity.ResSegmentData;
import com.sudo.dao.res.mapper.ResSegmentDataMapper;
import com.sudo.dao.res.model.bo.ResSegmentDataBo;
import com.sudo.service.admin.service.AdminBaseService;
import com.sudo.service.res.service.ResSegmentDataService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ResSegmentDataServiceImpl extends AdminBaseService implements ResSegmentDataService {

    @Resource
    private ResSegmentDataMapper resSegmentDataMapper;


    @Override
    public PagedGridResult queryResSegmentDataByPage(ResSegmentDataBo resSegmentDataBo) {
        PageHelper.startPage(resSegmentDataBo.getPage(), resSegmentDataBo.getPageSize());
        Example example = new Example(ResSegmentData.class);
        if (StringUtils.isNotBlank(resSegmentDataBo.getPhone())) {
            Example.Criteria criteria = example.createCriteria();
            String phone = resSegmentDataBo.getPhone().substring(0, 7);
            criteria.andEqualTo("top7", phone);
        }

        List<ResSegmentData> resSegmentDataList = resSegmentDataMapper.selectByExample(example);
        return setterPagedGrid(resSegmentDataList, resSegmentDataBo.getPage());
    }
}
